package org.framework.edu.auto;

import org.framework.edu.properties.JwtTokenProperties;
import org.framework.edu.service.JwtService;
import org.framework.edu.service.TokenService;
import org.framework.edu.service.impl.JwtServiceImpl;
import org.framework.edu.service.impl.TokenServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass({JwtService.class,TokenService.class})
@EnableConfigurationProperties(JwtTokenProperties.class)
public class JwtTokenServiceAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public JwtService jwtService(){
        return new JwtServiceImpl();
    }

    @Bean
    @ConditionalOnMissingBean
    public TokenService tokenService(JwtTokenProperties jwtTokenProperties){
        TokenServiceImpl tokenService = new TokenServiceImpl();
        tokenService.setJwtTokenProperties(jwtTokenProperties);
        return tokenService;
    }
}
